#!/bin/sh

. /usr/share/libubox/jshn.sh

case "$1" in
	list)
		echo '{ "on": { "name": "name" }, "off": { "name": "name" } }'
	;;
	call)
		# read the arguments
		read input
		json_load "$input"

		json_get_vars name
		
		[ -n "$name" ] || exit

		case "$2" in
			on)
			v=1
			;;
			off)
			v=0
			;;
		esac

		[ -n "$v" -a -f /sys/class/leds/$name/brightness ] || exit
		echo $v > /sys/class/leds/$name/brightness
		echo "{\"$name\": $v}"
	;;
esac
